Personal tools

Lua/Client/ClientStaticObject/Static Functions/Create

From JC2-MP Documentation

Jump to: navigation, search

Returns    ClientStaticObject
Prototype    ClientStaticObject.Create(table)
Description    Spawns a ClientStaticObject using an argument table.


Required values

Type Name Notes
Vector3 position
Angle angle
string model Path to the model file. See the model viewer for the full list.

Optional values

Type Name Default Notes
string collision "" Path to the collision file. See the model viewer for the full list.
boolean fixed true If false, the object will move smoothly and players can be transported while standing on it.

Notes

  • If collision isn't provided, or is invalid, the object will have no collision.
  • If fixed is false, you must provide a collision argument.

Example

Create a ramp in front of you when the horn button is pressed

Client
  1. pressed = false
  2. objects = {}
  3.  
  4. function SpawnRamp()
  5. 	local vehicle = LocalPlayer:GetVehicle()
  6.  
  7. 	-- Make sure they're in a vehicle
  8. 	if not IsValid(vehicle) then
  9. 		return
  10. 	end
  11.  
  12. 	local angle = vehicle:GetAngle()
  13. 	local direction = angle * Vector3.Forward
  14. 	-- Compensate for velocity. It doesn't always spawn instantly.
  15. 	local position = vehicle:GetPosition() + direction * 35
  16. 	angle = angle * Angle(math.pi * -0.5, 0, 0)
  17.  
  18. 	spawnArgs = {}
  19. 	spawnArgs.position = position
  20. 	spawnArgs.angle = angle
  21. 	spawnArgs.model = "17x48.fl/go666-b.lod"
  22. 	spawnArgs.collision = "17x48.fl/go666_lod1-b_col.pfx"
  23.  
  24. 	local object = ClientStaticObject.Create(spawnArgs)
  25. 	table.insert(objects, object)
  26. end
  27.  
  28. Events:Subscribe("PreTick", function()
  29. 	local currentlyPressed = Input:GetValue(Action.SoundHornSiren) > 0
  30. 	if currentlyPressed then
  31. 		if pressed == false then
  32. 			SpawnRamp()
  33. 		end
  34. 	end
  35.  
  36. 	pressed = currentlyPressed
  37. end)
  38.  
  39. -- Make sure to clean up everything on module unload.
  40. Events:Subscribe("ModuleUnload", function()
  41. 	for index, object in ipairs(objects) do
  42. 		object:Remove()
  43. 	end
  44. end)